Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

terser

Package Overview
Dependencies
Maintainers
1
Versions
182
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

terser

JavaScript parser, mangler/compressor and beautifier toolkit for ES6+

  • 5.36.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
37M
increased by4.07%
Maintainers
1
Weekly downloads
 
Created

What is terser?

The terser npm package is a tool for minifying and compressing JavaScript files. It removes unnecessary whitespace, shortens variable names, and performs various optimizations to reduce the size of your JavaScript files, which can lead to faster load times in web browsers.

What are terser's main functionalities?

Code Minification

Minifies JavaScript code by removing unnecessary characters without changing its functionality.

const Terser = require('terser');

const code = 'function add(x, y) { return x + y; }';
Terser.minify(code).then(result => {
  console.log(result.code); // Output could be 'function add(n,d){return n+d}'
});

Compressing Code

Compresses code by applying various transformations, such as removing unreachable code and simplifying if-statements.

const Terser = require('terser');

const code = 'if (true) { console.log('Hello World!'); }';
const options = { compress: true };
Terser.minify(code, options).then(result => {
  console.log(result.code); // Output could be 'console.log('Hello World!');'
});

Mangling Variable Names

Shortens variable and function names to reduce file size and potentially obfuscate code.

const Terser = require('terser');

const code = 'const longVariableName = 5; console.log(longVariableName);';
const options = { mangle: true };
Terser.minify(code, options).then(result => {
  console.log(result.code); // Output could be something like 'const a=5;console.log(a);'
});

Source Map Support

Generates source maps to help debug minified JavaScript by mapping the minified code back to the original source code.

const Terser = require('terser');

const code = 'function example() { console.log('Hello World!'); }';
const options = {
  sourceMap: {
    filename: 'out.js',
    url: 'out.js.map'
  }
};
Terser.minify(code, options).then(result => {
  console.log(result.code); // Minified code
  console.log(result.map);  // Source map
});

Other packages similar to terser

Keywords

FAQs

Package last updated on 16 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc